package com.xiaoman.pet;

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@State(
        name = "PetSettings",
        storages = @Storage("pet_settings.xml")
)
@Service(Service.Level.PROJECT)
public final class PetSettings implements PersistentStateComponent<PetSettings.State> {
    private State state = new State();

    public static class State {
        public String petName = "DefaultPet";
        public int moveInterval = 3000; // 移动间隔时间
    }

    @Nullable
    @Override
    public State getState() {
        return state;
    }

    @Override
    public void loadState(@NotNull State state) {
        this.state = state;
    }

    public static PetSettings getInstance(Project project) {
        return project.getService(PetSettings.class);
    }
}
